import http from '@/common/api/request'
import {getToken} from '@/request/token'
export function passwordLogin(loginMsg){
  return http.$axios({
    url:'/user/login',
    method:'post',
    data:{
      phone:loginMsg.phone,
      password:loginMsg.password
    },
  })
}

export function getUserInfo(token){
  return http.$axios({
    url:'/user/currentUser',
    headers:{
      token
    }
  })
}

export function sendMsg(user){
  return http.$axios({
    url:'/user/sendMsg',
    method:'post',
    data:{
      phone:user.phone
    }
  })
}

export function register(user){
  return http.$axios({
    url:'/user/register',
    method:'post',
    data:{
      phone:user.phone,
      password:user.password
    }
  })
}

export function msgLogin(user){
  return http.$axios({
    url:'/user/msgLogin',
    method:'post',
    data:{
      phone:user.phone
    }
  })
}

export function findPassword(user){
  return http.$axios({
    url:'/user/findPassword',
    method:'post',
    data:{
      phone:user.phone,
      password:user.password
    }
  })
}

export function updateInfo(user){
  return http.$axios({
    url:'/user/updateUser',
    method:'post',
    headers:{
      token:getToken()
    },
    data:{
      id:user.id,
      username:user.username,
      email:user.email,
      age:user.age,
      sex:user.sex
    }
  })
}

export function updateAvatar(user){
  return http.$axios({
    url:'/user/updateUser',
    method:'post',
    headers:{
      token:getToken()
    },
    data:{
      id:user.id,
      avatar:user.avatar
    }
  })
}
